﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Data.SqlTypes;

namespace DataAccess.Operate
{
   public class DA_Report_Attach_Operate:SqlInteractionBase
    {
       #region 自定义变量
       private DataEntity.T_Report_Attach _objMessage = null;
       #endregion

       public override bool Insert(object obj)
       {
           SqlCommand cmdToExecute = new SqlCommand();
           cmdToExecute.CommandText = "dbo.[sp_t_Report_Attach_Insert]";
           cmdToExecute.CommandType = CommandType.StoredProcedure;

           // Use base class' connection object
           cmdToExecute.Connection = _mainConnection;
           _objMessage=(DataEntity.T_Report_Attach)obj;
           try
           {
               cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_Report_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_Report_ID));
               cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_Report_MainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_Report_MainID));
               cmdToExecute.Parameters.Add(new SqlParameter("@iProject_Report_ExchangeTypeID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Project_Report_ExchangeTypeID));
               cmdToExecute.Parameters.Add(new SqlParameter("@iProject_Report_FileID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Project_Report_FileID));
               cmdToExecute.Parameters.Add(new SqlParameter("@sProject_Report_FileName", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_Report_FileName));
               cmdToExecute.Parameters.Add(new SqlParameter("@sProject_Report_FilePath", SqlDbType.NVarChar, 300, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_Report_FilePath));
               cmdToExecute.Parameters.Add(new SqlParameter("@sProject_Report_FileDesc", SqlDbType.NVarChar, 30, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_Report_FileDesc));

               if (_mainConnectionIsCreatedLocal)
               {
                   // Open connection.
                   _mainConnection.Open();
               }
               else
               {
                   if (_mainConnectionProvider.IsTransactionPending)
                   {
                       cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                   }
               }

               // Execute query.
               _rowsAffected = cmdToExecute.ExecuteNonQuery();
               return true;
           }
           catch (Exception ex)
           {
               // some error occured. Bubble it to caller and encapsulate Exception object
               throw new Exception("T_Report_Attach::Insert::Error occured.", ex);
           }
           finally
           {
               if (_mainConnectionIsCreatedLocal)
               {
                   // Close connection.
                   _mainConnection.Close();
               }
               cmdToExecute.Dispose();
           }
       }

       public override bool Delete(object obj)
       {
           SqlCommand cmdToExecute = new SqlCommand();
           cmdToExecute.CommandText = "dbo.[sp_t_Report_Attach_Delete]";
           cmdToExecute.CommandType = CommandType.StoredProcedure;

           // Use base class' connection object
           cmdToExecute.Connection = _mainConnection;

           try
           {
               cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_Report_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed,SqlGuid.Parse(obj.ToString())));

               if (_mainConnectionIsCreatedLocal)
               {
                   // Open connection.
                   _mainConnection.Open();
               }
               else
               {
                   if (_mainConnectionProvider.IsTransactionPending)
                   {
                       cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                   }
               }

               // Execute query.
               _rowsAffected = cmdToExecute.ExecuteNonQuery();
               return true;
           }
           catch (Exception ex)
           {
               // some error occured. Bubble it to caller and encapsulate Exception object
               throw new Exception("T_Report_Attach::Delete::Error occured.", ex);
           }
           finally
           {
               if (_mainConnectionIsCreatedLocal)
               {
                   // Close connection.
                   _mainConnection.Close();
               }
               cmdToExecute.Dispose();
           }
       }
    }
}
